/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TelaPrincipal.java
 *
 * Created on 12/04/2010, 19:00:00
 */

package Interface;

import Controle.ControlaData;
import event.DateEvent;
import event.DateEventListener;
import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Date;
import javax.swing.JLabel;
import javax.swing.JSpinner;

/**
 *
 * @author Jean
 */
public class TelaPrincipal extends javax.swing.JFrame {

    /** Creates new form TelaPrincipal */    
    ControlaData controle;
    private JLabel []cal ;
    private DateEventListener dateEventListener;

    public void setDateEventListener(DateEventListener dateEventListener) {
        this.dateEventListener = dateEventListener;
    }

    public TelaPrincipal(ControlaData ref, DateEventListener dateEventListener) {
        controle=ref;
        this.dateEventListener = dateEventListener;
        initComponents();
        this.setVisible(true);        
        this.setResizable(false);
        this.setLocationRelativeTo(null);
        this.montarCalendario();
    }
    
    public void montarCalendario(){    
        JLabel[] cal2 = {l0,l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12,l13,l14,
        l15,l16,l17,l18,l19,l20,l21,l22,l23,l24,l25,l26,l27,l28,l29,l30,l31,l32,
        l33,l34,l35,l36,l37,l38,l39,l40,l41};
        MouseListener listener = new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {

                DateEvent date =  new DateEvent(evt,((JLabel)evt.getSource()).getText());
                dateEventListener.dateChanged(date);
                //JLabel label = (JLabel) evt.getSource();;
            }
        };
        for (int i = 0; i < cal2.length; i++) {
            cal2[i].setText("");
            cal2[i].addMouseListener(listener);

        }
        int cont=1;
        int diaDaSemana=controle.retornaDiaSemana(jComboBox1.getSelectedIndex(), Integer.parseInt(sAno.getValue().toString()));
        int maximo=controle.retornaQtdDias(jComboBox1.getSelectedIndex(), Integer.parseInt(sAno.getValue().toString()));        
        for (int i = diaDaSemana; i < maximo+diaDaSemana; i++) {
            cal2[i].setText(new Integer(cont).toString());
            cont++;            
        }

    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelTopo = new javax.swing.JPanel();
        jComboBox1 = new javax.swing.JComboBox();
        sAno = new javax.swing.JSpinner();
        panelCalendario = new javax.swing.JPanel();
        l0 = new javax.swing.JLabel();
        l1 = new javax.swing.JLabel();
        l2 = new javax.swing.JLabel();
        l3 = new javax.swing.JLabel();
        l4 = new javax.swing.JLabel();
        l5 = new javax.swing.JLabel();
        l6 = new javax.swing.JLabel();
        l7 = new javax.swing.JLabel();
        l8 = new javax.swing.JLabel();
        l9 = new javax.swing.JLabel();
        l10 = new javax.swing.JLabel();
        l11 = new javax.swing.JLabel();
        l12 = new javax.swing.JLabel();
        l13 = new javax.swing.JLabel();
        l14 = new javax.swing.JLabel();
        l15 = new javax.swing.JLabel();
        l16 = new javax.swing.JLabel();
        l17 = new javax.swing.JLabel();
        l18 = new javax.swing.JLabel();
        l19 = new javax.swing.JLabel();
        l20 = new javax.swing.JLabel();
        l21 = new javax.swing.JLabel();
        l22 = new javax.swing.JLabel();
        l23 = new javax.swing.JLabel();
        l24 = new javax.swing.JLabel();
        l25 = new javax.swing.JLabel();
        l26 = new javax.swing.JLabel();
        l27 = new javax.swing.JLabel();
        l28 = new javax.swing.JLabel();
        l29 = new javax.swing.JLabel();
        l30 = new javax.swing.JLabel();
        l31 = new javax.swing.JLabel();
        l32 = new javax.swing.JLabel();
        l33 = new javax.swing.JLabel();
        l34 = new javax.swing.JLabel();
        l35 = new javax.swing.JLabel();
        l36 = new javax.swing.JLabel();
        l37 = new javax.swing.JLabel();
        l38 = new javax.swing.JLabel();
        l39 = new javax.swing.JLabel();
        l40 = new javax.swing.JLabel();
        l41 = new javax.swing.JLabel();
        panelSemana = new javax.swing.JPanel();
        dom = new javax.swing.JLabel();
        seg = new javax.swing.JLabel();
        ter = new javax.swing.JLabel();
        qua = new javax.swing.JLabel();
        qui = new javax.swing.JLabel();
        sex = new javax.swing.JLabel();
        sab = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Calendario");

        panelTopo.setBackground(new java.awt.Color(204, 204, 255));
        panelTopo.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro" }));
        jComboBox1.setSelectedIndex(controle.retornaMesAtual()-1);
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        sAno.setToolTipText("");
        sAno.setValue(new Integer(controle.retornaAnoAtual()));
        sAno.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                sAnoStateChanged(evt);
            }
        });

        javax.swing.GroupLayout panelTopoLayout = new javax.swing.GroupLayout(panelTopo);
        panelTopo.setLayout(panelTopoLayout);
        panelTopoLayout.setHorizontalGroup(
            panelTopoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTopoLayout.createSequentialGroup()
                .addGap(74, 74, 74)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(sAno, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(62, Short.MAX_VALUE))
        );
        panelTopoLayout.setVerticalGroup(
            panelTopoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTopoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelTopoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(sAno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelCalendario.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        panelCalendario.setToolTipText("2010");
        panelCalendario.setLayout(new java.awt.GridLayout(6, 7));

        l0.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l0);

        l1.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l1);

        l2.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l2);

        l3.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l3);

        l4.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l4);

        l5.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l5);

        l6.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l6);

        l7.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l7);

        l8.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l8);

        l9.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l9);

        l10.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l10);

        l11.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l11);

        l12.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l12);

        l13.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l13);

        l14.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l14);

        l15.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l15);

        l16.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l16);

        l17.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l17);

        l18.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l18);

        l19.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l19);

        l20.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l20);

        l21.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l21);

        l22.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l22);

        l23.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l23);

        l24.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l24);

        l25.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l25);

        l26.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l26);

        l27.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l27);

        l28.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l28);

        l29.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l29);

        l30.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l30);

        l31.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l31);

        l32.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l32);

        l33.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l33);

        l34.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l34);

        l35.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l35);

        l36.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l36);

        l37.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l37);

        l38.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l38);

        l39.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l39);

        l40.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l40);

        l41.setForeground(new java.awt.Color(51, 51, 255));
        panelCalendario.add(l41);

        panelSemana.setBackground(new java.awt.Color(153, 153, 153));
        panelSemana.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        panelSemana.setLayout(new java.awt.GridLayout(1, 0));

        dom.setFont(new java.awt.Font("Tahoma", 1, 12));
        dom.setText("Dom");
        panelSemana.add(dom);

        seg.setFont(new java.awt.Font("Tahoma", 1, 12));
        seg.setText("Seg");
        panelSemana.add(seg);

        ter.setFont(new java.awt.Font("Tahoma", 1, 12));
        ter.setText("Ter");
        panelSemana.add(ter);

        qua.setFont(new java.awt.Font("Tahoma", 1, 12));
        qua.setText("Qua");
        panelSemana.add(qua);

        qui.setFont(new java.awt.Font("Tahoma", 1, 12));
        qui.setText("Qui");
        panelSemana.add(qui);

        sex.setFont(new java.awt.Font("Tahoma", 1, 12));
        sex.setText("Sex");
        panelSemana.add(sex);

        sab.setFont(new java.awt.Font("Tahoma", 1, 12));
        sab.setText("Sab");
        panelSemana.add(sab);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelTopo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(panelSemana, javax.swing.GroupLayout.DEFAULT_SIZE, 285, Short.MAX_VALUE)
            .addComponent(panelCalendario, javax.swing.GroupLayout.DEFAULT_SIZE, 285, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(panelTopo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelSemana, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelCalendario, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        // TODO add your handling code here:
        this.montarCalendario();
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void sAnoStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_sAnoStateChanged
        // TODO add your handling code here:
        this.montarCalendario();
    }//GEN-LAST:event_sAnoStateChanged

    /**
    * @param args the command line arguments
    */
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel dom;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel l0;
    private javax.swing.JLabel l1;
    private javax.swing.JLabel l10;
    private javax.swing.JLabel l11;
    private javax.swing.JLabel l12;
    private javax.swing.JLabel l13;
    private javax.swing.JLabel l14;
    private javax.swing.JLabel l15;
    private javax.swing.JLabel l16;
    private javax.swing.JLabel l17;
    private javax.swing.JLabel l18;
    private javax.swing.JLabel l19;
    private javax.swing.JLabel l2;
    private javax.swing.JLabel l20;
    private javax.swing.JLabel l21;
    private javax.swing.JLabel l22;
    private javax.swing.JLabel l23;
    private javax.swing.JLabel l24;
    private javax.swing.JLabel l25;
    private javax.swing.JLabel l26;
    private javax.swing.JLabel l27;
    private javax.swing.JLabel l28;
    private javax.swing.JLabel l29;
    private javax.swing.JLabel l3;
    private javax.swing.JLabel l30;
    private javax.swing.JLabel l31;
    private javax.swing.JLabel l32;
    private javax.swing.JLabel l33;
    private javax.swing.JLabel l34;
    private javax.swing.JLabel l35;
    private javax.swing.JLabel l36;
    private javax.swing.JLabel l37;
    private javax.swing.JLabel l38;
    private javax.swing.JLabel l39;
    private javax.swing.JLabel l4;
    private javax.swing.JLabel l40;
    private javax.swing.JLabel l41;
    private javax.swing.JLabel l5;
    private javax.swing.JLabel l6;
    private javax.swing.JLabel l7;
    private javax.swing.JLabel l8;
    private javax.swing.JLabel l9;
    private javax.swing.JPanel panelCalendario;
    private javax.swing.JPanel panelSemana;
    private javax.swing.JPanel panelTopo;
    private javax.swing.JLabel qua;
    private javax.swing.JLabel qui;
    private javax.swing.JSpinner sAno;
    private javax.swing.JLabel sab;
    private javax.swing.JLabel seg;
    private javax.swing.JLabel sex;
    private javax.swing.JLabel ter;
    // End of variables declaration//GEN-END:variables

}
